#!/bin/bash

echo "执行迁移..."
python manage.py deploy  > logs/migrate.log 2>&1

# shellcheck disable=SC2236
if [[ ! -z `cat logs/migrate.log | grep -E "ERROR|Error"` ]]; then
    echo "迁移失败，请查看logs/migrate.log"
    exit 1
fi

echo "启动靶场服务..."
#exec "$@"
#uwsgi --ini deploy/test/uwsgi.ini || { echo "启动失败，请查看logs/deploy.log"; exit 1; }
gunicorn -c deploy/worker_config.py manage:app || { echo "启动失败，请查看logs/deploy.log"; exit 1; }

#echo "uwsgi状态监控..."
#uwsgi --connect-and-read uwsgi.status
#uwsgitop uwsgi.status
export TERM=xterm
#top -b

sleep 6

echo "错误日志监控..."
tail -f logs/gunicorn_error.log
